package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FeedBack;
import com.ruoyi.system.service.IFeedBackService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 留言反馈Controller
 * 
 * @author ruoyi
 * @date 2022-06-10
 */
@RestController
@RequestMapping("/system/back")
public class FeedBackController extends BaseController
{
    @Autowired
    private IFeedBackService feedBackService;

    /**
     * 查询留言反馈列表
     */
    @PreAuthorize("@ss.hasPermi('system:back:list')")
    @GetMapping("/list")
    public TableDataInfo list(FeedBack feedBack)
    {
        startPage();
        List<FeedBack> list = feedBackService.selectFeedBackList(feedBack);
        return getDataTable(list);
    }

    /**
     * 导出留言反馈列表
     */
    @PreAuthorize("@ss.hasPermi('system:back:export')")
    @Log(title = "留言反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FeedBack feedBack)
    {
        List<FeedBack> list = feedBackService.selectFeedBackList(feedBack);
        ExcelUtil<FeedBack> util = new ExcelUtil<FeedBack>(FeedBack.class);
        util.exportExcel(response, list, "留言反馈数据");
    }

    /**
     * 获取留言反馈详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:back:query')")
    @GetMapping(value = "/{feedBackId}")
    public AjaxResult getInfo(@PathVariable("feedBackId") Long feedBackId)
    {
        return AjaxResult.success(feedBackService.selectFeedBackByFeedBackId(feedBackId));
    }

    /**
     * 新增留言反馈
     */

    @Log(title = "留言反馈", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FeedBack feedBack)
    {
        feedBack.setCreaterId(getUserId());
        feedBack.setCreaterName(getUsername());
        feedBack.setCreateTime(new Date());
        return toAjax(feedBackService.insertFeedBack(feedBack));
    }

    /**
     * 修改留言反馈
     */
    @PreAuthorize("@ss.hasPermi('system:back:edit')")
    @Log(title = "留言反馈", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FeedBack feedBack)
    {
        return toAjax(feedBackService.updateFeedBack(feedBack));
    }

    /**
     * 删除留言反馈
     */
    @PreAuthorize("@ss.hasPermi('system:back:remove')")
    @Log(title = "留言反馈", businessType = BusinessType.DELETE)
	@DeleteMapping("/{feedBackIds}")
    public AjaxResult remove(@PathVariable Long[] feedBackIds)
    {
        return toAjax(feedBackService.deleteFeedBackByFeedBackIds(feedBackIds));
    }
}
